package com.kevin.ymqquan.adapter;

import java.util.List;

import com.kevin.ymqquan.R;
import com.kevin.ymqquan.bean.ClubListData;
import com.kevin.ymqquan.bean.CoachListData;
import com.kevin.ymqquan.cache.ImageLoader;
import com.kevin.ymqquan.fragment.ClubFragment;
import com.kevin.ymqquan.fragment.CoachFragment;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CoachListAdapter extends BaseAdapter {

	private CoachFragment mContext;
	private List<CoachListData> clubList;
	private LayoutInflater lf;
	private boolean mBusy = false;
	private ImageLoader mImageLoader;

	public void setFlagBusy(boolean busy) {
		this.mBusy = busy;
	}

	public CoachListAdapter(CoachFragment clubFra, List<CoachListData> clubList) {
		// TODO Auto-generated constructor stub
		this.mContext = clubFra;
		this.clubList = clubList;
		mImageLoader = new ImageLoader(mContext.getActivity());
		this.lf = (LayoutInflater) mContext.getActivity().getSystemService(
				Context.LAYOUT_INFLATER_SERVICE);
	}

	public ImageLoader getImageLoader() {
		return mImageLoader;
	}

	@Override
	public int getCount() {
		return clubList.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return clubList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ClubHolder holder = null;
		holder = new ClubHolder();

		// 自定义视图
		if (convertView == null) {

			convertView = lf.inflate(R.layout.list_coach_item, parent, false);
			holder.tv_club_item_name = (TextView) convertView
					.findViewById(R.id.tv_club_item_name);
			holder.tv_club_item_owner = (TextView) convertView
					.findViewById(R.id.tv_club_item_owner);
			holder.tv_club_item_membercount = (TextView) convertView
					.findViewById(R.id.tv_club_item_membercount);
			holder.iv_club_item_logo = (ImageView) convertView
					.findViewById(R.id.iv_logo_item_logo);
//			holder.iv_club_item_logo.setBackgroundResource(R.drawable.woman_user);
			convertView.setTag(holder);
		} else {
			holder = (ClubHolder) convertView.getTag();
		}

		holder.tv_club_item_name.setText(clubList.get(position).getCoachName());
		holder.tv_club_item_membercount.setText(clubList.get(position)
				.getLevel());
		holder.tv_club_item_owner.setText(clubList.get(position).getArea());

		// Log.i("kevinlog", clubList.get(position).getClubLogoUrl());
		
		mImageLoader.DisplayImage(clubList.get(position).getCoachLogoUrl(),
				holder.iv_club_item_logo, false);
		return convertView;
	}

	/**
	 * 自定义控件集合
	 */
	public static class ClubHolder {
		// 名称
		public TextView tv_club_item_name;
		// 所有人
		public TextView tv_club_item_owner;
		// 会员人数
		public TextView tv_club_item_membercount;
		// logo
		public ImageView iv_club_item_logo;
	}

}
